﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/AdminSite.Master" Inherits="System.Web.Mvc.ViewPage<List<Sys.WebRes.Publish.Areas.Admin.Models.AttachmentModel>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	批量上传
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="BodyContent" runat="server">
<fieldset>
    <legend>附件上传一览</legend>
    <% using (Html.BeginForm(null, null, FormMethod.Post, new {enctype="multipart/form-data"})) {%>
    <table id="fileTable" width="100%" count="<%=Model.Count %>">
        <tr>
            <td width="100">
                
            </td>
            <td>
                <%=Html.TextBox("uploadFolder", null, new {@size = 30 })%><label for="uploadFolder">(上传至)</label>
            </td>
        </tr>
    <% for (var i = 0; i < Model.Count; i++ ){ %>
        <tr class="fileRow">
            <td>
                <img id="_<%=i %>__Img" src="<%=Url.Action("Thumb", "Attachment", new { Area="", path=Model[i].FilePath}) %>" width="100" alt="预览"/>
            </td>
            <td>
                <input type="file" id="file1" name="[<%=i %>].File" size="50" /><br />
                <%=Html.TextBoxFor(model => model[i].FilePath, new { @readonly = true, @size = 50, @id = string.Format("_{0}__FilePath", i) })%>
                <label for="_<%=i %>__FilePath">(上传路径)</label><br />
                <%=Html.TextBoxFor(model => model[i].Title, new { @id = string.Format("_{0}__Title", i) })%>
                <label for="_<%=i %>__Title">(标题)</label><br />
                <%=Html.TextAreaFor(model => model[i].Summary, new { @rows = 2, @cols = 50, @id = string.Format("_{0}__Summary", i) })%>
                <label for="_<%=i %>__Summary">(概要)</label><br />
                <%=Html.TextBoxFor(model => model[i].CustomType, new { @size = 30, @id = string.Format("_{0}__CustomType", i) })%>
                <label for="_<%=i %>__CustomType">(自定义分类)</label>
            </td>
        </tr>
    <% } %>

    </table>
    <div>(<a href="javascript:void(0);" id="addFileBtn">添加行</a>)<br /></div>
    <div class="operDiv" style="text-align:right; height:22px;">
        <a class="easyui-linkbutton" href="javascript:document.forms[0].submit();" onclick="">批量上传</a>
        <a class="easyui-linkbutton" href="javascript:void(0)" onclick="cancel()">取消</a>
    </div>
    <%}%>
</fieldset>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
<script language="javascript" type="text/javascript">
    $().ready(function () {
        $(".fileRow:even").css({ background: "#ddddff" });
        $("#addFileBtn").click(function () {
            addLine();
        });
    });

    function addLine() {
        var count = $("#fileTable")[0].count;
        $("#fileTable")[0].count = Number(count) + 1;
        var content = $(".fileRow:first").html();
        content = content.replace(/\[\d\]/ig, "[" + count + "]");
        content = content.replace(/_\d__/ig, "_" + count + "__");
        content = content.replace(/\(\d\)/ig, "(" + count + ")");
        $("<tr class='fileRow'>" + content + "</tr>").appendTo("#fileTable");

        setLineValue(count);

        $(".fileRow:even").css({ background: "#ddddff" });
    }

    function setLineValue(index) {
        $("#_" + index + "__Img")[0].src = '<%=Url.Action("Pic", "Attachment", new {Area="", path="noimage.gif"}) %>';
        $("#_" + index + "__Path").val("");
        $("#_" + index + "__Title").val("");
        $("#_" + index + "__Summary").val("");
    }
</script>
</asp:Content>

